package br.com.cpqd.ssar.utilitarias;

import java.util.LinkedList;

public class Tijolo extends AtributosGeometria {

    private float[] firstPoint;
    private float[] secondPoint;
    private LinkedList listTriangle = new LinkedList();
    private Triangulo[] listaTriangulos = null;

    /**
     * 
     * @param firstP
     * @param secondP
     * @param reference
     * @param id
     */
    public Tijolo(float[] firstP, float[] secondP, float[] reference, int id) {

        super(reference, id);
        this.firstPoint = firstP;
        this.secondPoint = secondP;

    }

    /**
     * Translada uma unidade no eixo Y
     */
    public void addY() {
        firstPoint[1] += 1;
        secondPoint[1] += 1;
    }

    /**
     * Translada uma unidade no eixo Z
     */
    public void addZ() {
        firstPoint[2] += 1;
        secondPoint[2] += 1;
    }

    /**
     * Retorna primeiro ponto do Tijolo
     * firstPoint[0] = coordenada X;
     * firstPoint[1] = coordenada Y;
     * firstPoint[2] = coordenada Z;
     * @return firstPoint - []float
     */
    public float[] getFirsPoint() {
        return firstPoint;
    }

    /**
     * Seta o primeiro ponto do Tijolo
     * firstPoint[0] = coordenada X;
     * firstPoint[1] = coordenada Y;
     * firstPoint[2] = coordenada Z;
     * @return firstPoint - []float
     */
    public void setFirsPoint(float[] firstPoint) {
        this.firstPoint = firstPoint;
    }

    /**
     * Retorna o segundo ponto do Tijolo
     * secondPoint[0] = coordenada X;
     * secondPoint[1] = coordenada Y;
     * secondPoint[2] = coordenada Z;
     * @return secondPoint - []float
     */
    public float[] getSecondPoint() {
        return secondPoint;
    }

    /**
     * Seta o segundo ponto do Tijolo
     * secondPoint[0] = coordenada X;
     * secondPoint[1] = coordenada Y;
     * secondPoint[2] = coordenada Z;
     * @return secondPoint - []float
     */
    public void setSecondPoint(float[] secondPoint) {
        this.secondPoint = secondPoint;
    }

    /**
     * Triangulariza Geometria
     * @return listaTriangulos[] - Triangulo[]
     */
    public Triangulo[] triangularizarGeometria() {
        listaTriangulos = new Triangulo[0];
        listTriangle.clear();

        float[] vectorNormal = new float[3];
        Vertice v1 = new Vertice();
        Vertice v2 = new Vertice();
        Vertice v3 = new Vertice();
        Vertice v4 = new Vertice();
        Vertice v5 = new Vertice();
        Vertice v6 = new Vertice();
        Vertice v7 = new Vertice();
        Vertice v8 = new Vertice();


        v1.setCoordenada(0, (firstPoint[0]));
        v1.setCoordenada(1, (firstPoint[1]));
        v1.setCoordenada(2, (firstPoint[2]));

        v2.setCoordenada(0, (firstPoint[0]));
        v2.setCoordenada(1, (secondPoint[1]));
        v2.setCoordenada(2, (firstPoint[2]));

        v3.setCoordenada(0, (secondPoint[0]));
        v3.setCoordenada(1, (secondPoint[1]));
        v3.setCoordenada(2, (firstPoint[2]));

        v4.setCoordenada(0, (secondPoint[0]));
        v4.setCoordenada(1, (firstPoint[1]));
        v4.setCoordenada(2, (firstPoint[2]));

        v5.setCoordenada(0, (firstPoint[0]));
        v5.setCoordenada(1, (firstPoint[1]));
        v5.setCoordenada(2, (secondPoint[2]));

        v6.setCoordenada(0, (firstPoint[0]));
        v6.setCoordenada(1, (secondPoint[1]));
        v6.setCoordenada(2, (secondPoint[2]));

        v7.setCoordenada(0, (secondPoint[0]));
        v7.setCoordenada(1, (secondPoint[1]));
        v7.setCoordenada(2, (secondPoint[2]));

        v8.setCoordenada(0, (secondPoint[0]));
        v8.setCoordenada(1, (firstPoint[1]));
        v8.setCoordenada(2, (secondPoint[2]));

        Vertice[] vVertex = new Vertice[3];

        vectorNormal = super.calcVetorNormal(v1, v2, v3);
        vVertex[0] = v1;
        vVertex[1] = v2;
        vVertex[2] = v3;
        /* v1,v2 e v3 formam uma face e sao guardados em um vetor 'vVertex'
         *pois a classe 'TriangleElement' aceita como parametro um vetor
         *de com 3 elementos 'Vertice' e um vetor 'float' com a normal', assim
         *'listVertex0' representa a face 0 do 'brick' com o 'TriangleElement'
         *armazenado.
         */
        Triangulo triangleFace1 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace1);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v3, v4, v1);
        vVertex[0] = v3;
        vVertex[1] = v4;
        vVertex[2] = v1;
        Triangulo triangleFace2 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace2);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v4, v3, v7);
        vVertex[0] = v4;
        vVertex[1] = v3;
        vVertex[2] = v7;
        Triangulo triangleFace3 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace3);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v7, v8, v4);
        vVertex[0] = v7;
        vVertex[1] = v8;
        vVertex[2] = v4;
        Triangulo triangleFace4 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace4);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v1, v5, v8);
        vVertex[0] = v1;
        vVertex[1] = v5;
        vVertex[2] = v8;
        Triangulo triangleFace5 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace5);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v8, v4, v1);
        vVertex[0] = v8;
        vVertex[1] = v4;
        vVertex[2] = v1;
        Triangulo triangleFace6 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace6);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v1, v2, v6);
        vVertex[0] = v1;
        vVertex[1] = v2;
        vVertex[2] = v6;
        Triangulo triangleFace7 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace7);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v6, v5, v1);
        vVertex[0] = v6;
        vVertex[1] = v5;
        vVertex[2] = v1;
        Triangulo triangleFace8 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace8);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v6, v7, v5);
        vVertex[0] = v6;
        vVertex[1] = v7;
        vVertex[2] = v5;
        Triangulo triangleFace9 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace9);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v7, v8, v5);
        vVertex[0] = v7;
        vVertex[1] = v8;
        vVertex[2] = v5;
        Triangulo triangleFace10 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace10);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v2, v6, v7);
        vVertex[0] = v2;
        vVertex[1] = v6;
        vVertex[2] = v7;
        Triangulo triangleFace11 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace11);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        vectorNormal = this.calcVetorNormal(v7, v3, v2);
        vVertex[0] = v7;
        vVertex[1] = v3;
        vVertex[2] = v2;
        Triangulo triangleFace12 = new Triangulo(vVertex, vectorNormal);
        listTriangle.add(triangleFace12);
        vVertex = new Vertice[3];
        vectorNormal = new float[3];

        listaTriangulos = new Triangulo[listTriangle.size()];
        for (int i = 0; i < listTriangle.size(); i++) {
            listaTriangulos[i] = (Triangulo) listTriangle.get(i);
        }
        return listaTriangulos;

    }

    @Override
    public void setRaio(float radius) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public float getRaio() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public float getAltura() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setAltura(float height) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getDiscretizacaoX() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setDiscretizacaoX(int discretizacaoX) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getDiscretizacaoY() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setDiscretizacaoY(int discretizacaoY) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getDiscretizacaoZ() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setDiscretizacaoZ(int discretizacaoZ) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getDx() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getDy() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getDz() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlXi() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlXi(int pmlXi) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlXf() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlXf(int pmlXf) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlYi() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlYi(int pmlYi) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlYf() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlYf(int pmlYf) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlZi() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlZi(int pmlZi) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlZf() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlZf(int pmlZf) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getEscala() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setEscala(double escala) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setEscala(String tipo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addX() {
        firstPoint[0] += 1;
        secondPoint[0] += 1;
    }

    @Override
    public void subX() {
        firstPoint[0] -= 1;
        secondPoint[0] -= 1;
    }

    @Override
    public void subY() {
        firstPoint[1] -= 1;
        secondPoint[1] -= 1;
    }

    @Override
    public void subZ() {
        firstPoint[2] -= 1;
        secondPoint[2] -= 1;
    }

    @Override
    public void redimensionar() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getCaminhoArquivo() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setCaminhoArquivo(String caminhoArquivo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getNSteps() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addX(float valor) {
        firstPoint[0] += valor;
        secondPoint[0] += valor;
    }

    @Override
    public void addY(float valor) {
        firstPoint[1] += valor;
        secondPoint[1] += valor;
    }

    @Override
    public void addZ(float valor) {
        firstPoint[2] += valor;
        secondPoint[2] += valor;
    }

    @Override
    public void setNElements(int n) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Triangulo[] getListaTriangulosSTL() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getNElements() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void redimensionarSTL(float[] min, float[] max) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void subX(float valor) {
        firstPoint[0] -= valor;
        secondPoint[0] -= valor;
    }

    @Override
    public void subY(float valor) {
        firstPoint[1] -= valor;
        secondPoint[1] -= valor;
    }

    @Override
    public void subZ(float valor) {
        firstPoint[2] -= valor;
        secondPoint[2] -= valor;
    }
}
